package com.bufbomb.datastore;

public class StoreController {
	/*public static boolean addBlob(User u, BlobKey k)
	{
		boolean result = true;
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try
		{
			Query query = pm.newQuery(StoreUser.class);
			query.setFilter("email==targetEmail");
			query.declareParameters("String targetEmail");
			List<StoreUser> records = (List<StoreUser>) query.execute(u.getEmail()); 
			if (records.isEmpty()) {
				result = false;
			}
			else
			{
				StoreUser su = records.get(0);
				su.addBlob(k);
				pm.makePersistent(su);
			}
		}
		finally
		{
			pm.close();
		}
		return result;
	}
	
	public static boolean removeBlob(User u, BlobKey k)
	{
		boolean result = true;
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try
		{
			Query query = pm.newQuery(StoreUser.class);
			query.setFilter("email==targetEmail");
			query.declareParameters("String targetEmail");
			List<StoreUser> records = (List<StoreUser>) query.execute(u.getEmail()); 
			if (records.isEmpty()) {
				result = false;
			}
			else
			{
				StoreUser su = records.get(0);
				su.removeBlob(k);
				pm.makePersistent(su);
			}
		}
		finally
		{
			pm.close();
		}
		return result;
	}

	public static ArrayList<BlobKey> getBlobs(User u)
	{
		ArrayList<BlobKey> result = null;
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try 
		{
			Query query = pm.newQuery(StoreUser.class);
			query.setFilter("email==targetEmail");
			query.declareParameters("String targetEmail");
			List<StoreUser> records = (List<StoreUser>) query.execute(u.getEmail()); 
			if (!records.isEmpty()) {
				StoreUser su = records.get(0);
				result = su.getBlobs();
			}
		}
		finally {
			pm.close();
		}
		return result;
	}*/
}
